<template>
  <el-menu
    :default-active="activeItem"
    class="el-menu-vertical-demo"
    router
    background-color="#fff"
    text-color="#000"
    active-text-color="#209dfc"
    style="text-align: center"
  >
    <el-menu-item
      v-for="item in noChildren"
      :key="item.path"
      :index="item.path"
    >
      <i :class="`el-icon-${item.icon}`"></i>
      <span slot="title">{{ item.name }}</span>
    </el-menu-item>
    <!-- 有子选项的 -->
    <el-submenu v-for="item in hasChildren" :key="item.path" :index="item.path">
      <template slot="title">{{ item.name }}</template>
      <el-menu-item
        v-for="subMenu in item.children"
        :key="subMenu.path"
        :index="subMenu.path"
        >{{ subMenu.name }}</el-menu-item
      >
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  name: "CommonAside",
  props: ["menus"],
  computed: {
    noChildren() {
      return this.menus.filter((v) => !v.children);
    },
    hasChildren() {
      return this.menus.filter((v) => v.children);
    },
    activeItem() {
      const { path } = this.$route;
      // console.log("path: ", path);
      // return path;
      return path.split("/").length === 2 ? this.menus[0].path : path;
    },
  },
  mounted() {
    this.$router.replace(this.activeItem).catch((err) => err);
  },
};
</script>                                                                                                          +